package com.example.human_resource_management.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.human_resource_management.entry.po.Department;
import com.example.human_resource_management.service.DepartmentService;
import com.example.human_resource_management.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【department(部门表)】的数据库操作Service实现
* @createDate 2025-06-09 08:49:00
*/
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department>
    implements DepartmentService{
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> getAllDepartments() {
        return departmentMapper.selectList(null);
    }

    @Override
    public Department getDepartmentById(Long deptId) {
        return departmentMapper.selectById(deptId);
    }

    @Override
    public boolean addDepartment(Department department) {
        return save(department);
    }

    @Override
    public boolean updateDepartment(Department department) {
        return updateById(department);
    }

    @Transactional
    @Override
    public boolean deleteDepartment(Long deptId) {
        // 检查是否有职位关联此部门
        // 检查是否有员工关联此部门
        // 这里需要根据实际业务逻辑处理关联数据
        // 例如，可以先删除关联的职位，或者将关联的员工转移到其他部门

        return removeById(deptId);
    }
}




